package org.tis.tools.senior.module.developer.entity.enums;


import org.tis.tools.model.enums.BaseEnum;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * description:
 * JAR 输出为jar包
 * ECD 输出为ecd包
 * EPD 输出为epd
 * CFG 作为配置文件
 * DBV 作为数据库脚本（SQL、DDL等数据库版本脚本）
 *
 * @author zhaoch
 * @date 2018/6/24
 **/
public enum PatchType implements BaseEnum {

    ECD("ecd"),
    EPD("epd"),
    JAR("jar"),
    EXE_JAR("可执行jar"),
    PLUGINS("plugins"),
    DBV("sql"),
    CFG("配置文件"),
    WAR("war");

    private final String value;

    PatchType(final String value) {
        this.value = value;
    }

    @Override
    public Serializable deserialze() {
        return value;
    }

    @Override
    public Serializable getValue() {
        return value;
    }

    @Override
    public String toString() {
        return value;
    }

    public static List<Map<String,Object>> getPatchType(ProjectType projectType){
        List<Map<String,Object>> patchMapLists = new ArrayList<>();
        switch (projectType){
            case IBS:
                for (PatchType patchType:PatchType.values()) {
                    if (ECD.equals(patchType) || EPD.equals(patchType)) {
                        Map<String,Object> deployMap = new HashMap<>();
                        deployMap.put("name", patchType);
                        deployMap.put("children",DeployWhere.getDeployWhere(patchType));
                        patchMapLists.add(deployMap);
                    }
                }
                break;
            case JAVA:
                for (PatchType patchType:PatchType.values()) {
                    if(JAR.equals(patchType) || EXE_JAR.equals(patchType)){
                        Map<String,Object> deployMap = new HashMap<>();
                        deployMap.put("name", patchType);
                        deployMap.put("children",DeployWhere.getDeployWhere(patchType));
                        patchMapLists.add(deployMap);
                    }
                }
                break;
            case SPECIAL:
                for (PatchType patchType:PatchType.values()) {
                    if(DBV.equals(patchType) || CFG.equals(patchType) || JAR.equals(patchType)){
                        Map<String,Object> deployMap = new HashMap<>();
                        deployMap.put("name", patchType);
                        deployMap.put("children",DeployWhere.getDeployWhere(patchType));
                        patchMapLists.add(deployMap);
                    }
                }
                break;
            case PLUGINS:
                for (PatchType patchType:PatchType.values()) {
                    if(PLUGINS.equals(patchType) || JAR.equals(patchType)){
                        Map<String,Object> deployMap = new HashMap<>();
                        deployMap.put("name", patchType);
                        deployMap.put("children",DeployWhere.getDeployWhere(patchType));
                        patchMapLists.add(deployMap);
                    }
                }
                break;
            default:
                patchMapLists.add(null);
                break;
        }
        return patchMapLists;
    }

}
